package common.dtos;

import common.enums.HttpCodeEnum;
import lombok.Getter;

import java.io.Serializable;

/**
 * @Author: 郑国荣
 * @Date: 2024-02-22-14:54
 * @Description:
 */
@Getter
public class ResponseResult<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;


    public ResponseResult() {
        this.code = 200;
    }

    public ResponseResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, String msg) {
        this.code = httpCodeEnum.getCode();
        this.msg = msg;
    }

    public ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, String msg, T data) {
        this.code = httpCodeEnum.getCode();
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum, T data) {
        this.code = httpCodeEnum.getCode();
        this.msg = httpCodeEnum.getMsg();
        this.data = data;
    }

    public ResponseResult(HttpCodeEnum httpCodeEnum) {
        this.code=httpCodeEnum.getCode();
        this.msg=httpCodeEnum.getMsg();
    }

    public static ResponseResult<?> get() {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(HttpCodeEnum.SUCCESS);
        return responseResult;
    }

    public static ResponseResult<?> get(HttpCodeEnum httpCodeEnum) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(httpCodeEnum);
        return responseResult;
    }

    public static ResponseResult<?> get(HttpCodeEnum httpCodeEnum, String msg) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = httpCodeEnum.getCode();
        responseResult.msg = msg;
        return responseResult;
    }

    public ResponseResult<?> get(HttpCodeEnum httpCodeEnum, String msg, T data) {
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.code = httpCodeEnum.getCode();
        responseResult.msg = msg;
        responseResult.data = data;
        return responseResult;
    }

    public ResponseResult<T> get(HttpCodeEnum httpCodeEnum, T data) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setHttpCodeEnum(httpCodeEnum);
        responseResult.data = data;
        return responseResult;
    }

    private void setHttpCodeEnum(HttpCodeEnum httpCodeEnum) {
        this.code = httpCodeEnum.getCode();
        this.msg = httpCodeEnum.getMsg();
    }
}
